<template>
  <div>
    <el-main :style="{ '--zoom': zoom }">
      <el-row>
        <el-col>
          <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane v-for="item in tabsList" :key="item.id" :label="item.name" :name="item.id">
              <honortabs
                @getSearch="getSearch"
                @changeYears="changeYears"
                @changePrize="changePrize"
                @changeAddress="changeAddress"
                @currentChange="currentChange"
                :tableData="tableData"
                :yearlist="yearlist"
                :prizelist="prizelist"
                :addresslist="addresslist"
                :page="honorListForm.page"
                :count="count"
                :activeName="Number(activeName)"
              >
              </honortabs>
            </el-tab-pane>
          </el-tabs>
        </el-col>
      </el-row>
    </el-main>
  </div>
</template>

<script>
import { getPrizeYears, getExamplesList } from "@/api/web";
import { honorType,yearList,honorList } from "@/api/configApi";
import honortabs from "./components/honortabs.vue";

export default {
  components: { honortabs },
  data() {
    return {
      zoom: 1,
      activeName: "1",
      activeNumber: 2,
      tableData: [],
      yearlist: [],
      prizelist: [
        {
          id: '1',
          name: '中国专利金奖'
        },
        {
          id: '2',
          name: '中国专利银奖'
        },
        {
          id: '3',
          name: '中国专利优秀奖'
        },
        {
          id: '4',
          name: '中国外观设计金奖'
        },
        {
          id: '5',
          name: '中国外观设计银奖'
        },
        {
          id: '6',
          name: '中国外观设计优秀奖'
        },
        {
          id: '7',
          name: ' 广东省专利金奖'
        },
        {
          id: '8',
          name: '广东省专利银奖'
        },
        {
          id: '9',
          name: '广东省专利优秀奖'
        }
      ],
      addresslist: [],
      year: "",
      prize: "",
      honorListForm: {
        page: 1,
        limit: 10,
        keywords: '',
        region_id: this.$store.state.user.region_id,
        year: '',
        type_id:'',
      },
      getPrizeYearsForm: {
        address: "",
        prize_name: "",
        table: "examples",
        type: 1,
        years: "",
      },
      count: 0,
      tabsList: [
        {
          id: '1',
          name: "专利奖",
        },
        {
          id: '10',
          name: "国家示范企业",
        },
        {
          id: '12',
          name: "省级示范企业",
        },
        {
          id: '11',
          name: "国家优势企业",
        },
      ],
      region_id: this.$store.state.user.region_id,
    };
  },
  mounted() {
    this.yearList()
    this.honorList()

    let width = document.documentElement.clientWidth || document.body.clientWidth;
    this.zoom = width / 1920;
  },
  methods: {
    yearList(){
      yearList({
        region_id : this.region_id
      }).then(res => {
        this.yearlist = res.years;
      })
    },
    getSearch(search) {
      this.honorListForm.keywords = search;
      this.honorList()
    },
    changeAddress(address) {
      this.honorListForm.address = address;
      if (this.activeNumber == 0) {
        this.getExamplesList();
      } else if (this.activeNumber == 4) {
      } else {
        this.getExamplesList();
      }
    },
    changePrize(prize) {
      this.honorListForm.page = 1
      this.honorListForm.type_id = prize
      honorList(
        {
          type: 1,
          ...this.honorListForm,
        }).then((res) => {
        this.tableData = res.list;
        this.count = res.count;
      });
    },
    changeYears(year) {
      this.honorListForm.page = 1
      this.honorListForm.year = year;
      this.honorList()
    },
    currentChange(page) {
      this.honorListForm.page = page;
      

    },
    honorList() {
      honorList(
        {
          type: Number(this.activeName) == 1 ? 1 : 2,
          ...this.honorListForm,
        }).then((res) => {
        this.tableData = res.list;
        this.count = res.count;
      });
    },
    getExamplesList() {
      getExamplesList(this.honorListForm).then((res) => {
        this.tableData = res.list;
        this.count = res.count;
      });
    },

    getPrizeYears() {
      getPrizeYears(this.getPrizeYearsForm).then((res) => {
        this.yearlist = res.years;
        if (res.prize_name) {
          this.prizelist = res.prize_name;
        }
        this.addresslist = res.address;
      });
    },
    handleClick(tab, event) {
      this.honorListForm = {
        page: 1,
        limit: 10,
        keywords: '',
        region_id: this.region_id,
        year: '',
        type_id: tab.name == 1 ? '' : tab.name,
      }

      console.log( );
      this.activeNumber = tab.name;
      this.honorList()
    },
    ResetForm() {
      this.getPrizeYearsForm = {
        address: "",
        prize_name: "",
        table: "patent",
        type: null,
        years: "",
      };
      this.honorListForm = {
        years: "",
        address: "",
        prize_name: "",
        page: 1,
      };
    },
  },
};
</script>

<style scoped lang="less">
.el-main {
  zoom: var(--zoom);
}
::v-deep .el-input__inner {
}

::v-deep .el-input__icon {
  line-height: 38px;
  font-size: 16px;
}

.mr {
  margin-bottom: 20px;
}

.mr:hover {
  background: #f4f5f7;
  cursor: pointer;
}

.el-main {
  margin: 25px 30px 0 30px;
  border-radius: 5px;
}

::v-deep .el-tabs__item {
  padding: 0 52px;
  font-size: 16px;
}

::v-deep input {
  border-radius: 30px;
  height: 38px;
  font-size: 16px;
}

::v-deep .el-table_1_column_5 {
  text-align: center;
}

.b_table {
  margin-top: 15px;
}

.button_ys {
  background-color: #387dff;
  height: 30px;
  line-height: 5px;
  padding: 10px 40px;
}

@media (max-width: 1360px) {
}

@media (max-width: 1280px) {
}
</style>
